/**
CDb: Singleton Class, DB connection.
**/
#pragma once

#ifndef _CDB_H_
#define _CDB_H_

#include "pThreads/semaphore.h"
#include "CSemaphore.h"
#include "MySQL/mysql.h"
#include <vector>

#define NUMJOBS 20
#define NUMRANKS 12

class CDb {
private:
	static CDb * _instance;

	CDb();
	~CDb();

	char** m_pSkillRanks; 
	unsigned char maxWeaponSkillId;
	unsigned short** m_pSkillCap;
	unsigned char maxLevel;

	//static sem_t CDb::numMysqlConnSemaphore;
	static int CDb::numMysqlConn;
	static CSemaphore* CDb::numMysqlConnSemaphore;

	//static sem_t CDb::mysqlConnListMutex;
	static CSemaphore* CDb::mysqlConnListMutex;
	//static sem_t CDb::mysqlConnListCountSemaphore;
	static CSemaphore* CDb::mysqlConnListCountSemaphore;
	static std::vector<MYSQL*> CDb::mysqlConnList;

public:
	static CDb* CDb::getObj();
	static MYSQL* CDb::getConn(); 
	static void CDb::pushConn(MYSQL* mysql); 
	bool CDb::startMySQL();
	static void CDb::closeConn();
	static int CDb::loadCharacters();

	void loadWeaponskillRanks(void);
	void loadWeaponskillCaps(void);
	unsigned short getMaxWeaponSkill(unsigned short weaponSkillId, unsigned char jobId, unsigned char level);
};


#endif